#!/bin/bash
#description Create a virtual host based on the domain name specified in the domain.txt file
InstallDir=/data/application/nginx/
Log="/data/log/nginx/"
Dir="/usr/local/src"
[ ! -d $Log ] && mkdir -p $Log
for line in $(cat domain.txt);do
	directory="/data/$line/www.$line"
	[ ! -d $directory ] && mkdir -p $directory
done

while read domain;do
	cat > ${InstallDir}/conf.d/$domain.conf <<EOF
		server {
			listen 80;
			server_name www.$domain;
			access_log ${Log}/${domain}_access.log main;
			error_log ${Log}/${domain}_error.log;
		location / {
			root /data/$domain/www.$domain;
			index index.html index.html;
		}
		#location ~ \.php/?.*$ {
        	#	root        /data/$domain/www.$domian;
        	#	fastcgi_pass   127.0.0.1:9000;
       		#	fastcgi_index  index.php;
        	#	include        fastcgi.conf;
        	#	set $fastcgi_script_name2 $fastcgi_script_name;
        	#	if ($fastcgi_script_name ~ "^(.+\.php)(/.+)$") {
            	#		set $fastcgi_script_name2 $1;
            	#		set $path_info $2;
        	#	}
        	#	fastcgi_param   PATH_INFO $path_info;
        	#	fastcgi_param   SCRIPT_FILENAME   $document_root$fastcgi_script_name2;
        	#	fastcgi_param   SCRIPT_NAME   $fastcgi_script_name2;
    		#}
EOF
echo "/data/application/nginx/conf.d/$domain.conf is successful"
done < ${Dir}/domain.txt

	
